package com.kadron.dao;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;

import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.intercept.BypassInterceptors;

import com.kadron.entity.Embed;

@AutoCreate
@BypassInterceptors
@Name("embedDAO")
public class KEmbedDAO extends KDAO<Embed> {

	public Embed getNew() {
		EntityManager em = getEntityManager();
		try {			
			return (Embed) em.createQuery("SELECT e FROM Embed e WHERE e.active=TRUE ORDER BY e.id DESC")
			.setMaxResults(1)
			.getSingleResult();
		} catch (NoResultException e) {
			return null;
		}
	}
	
}
